#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minOperations(vector<int>& nums, int x)
    {
        int left = 0, right = 0;
        int sum1 = 0;
        for (auto num : nums)
        {
            sum1 += num;
        }

        int target = sum1 - x;
        if (target < 0)
        {
            return -1;
        }
        int ret = -1;
        int sum2 = 0;
        while (right < nums.size())
        {
            sum2 += nums[right];
            while (sum2 > target)
            {
                sum2 -= nums[left++];
            }
            if (sum2 == target)
            {
                ret = max(ret, right - left + 1);
            }
            right++;
        }
        return ret = (ret == -1) ? ret : nums.size() - ret;
    }
};
//////////////////////////////
class Solution {
public:
    int longestOnes(vector<int>& nums, int k)
    {
        int zero = 0;
        int left = 0, right = 0;
        int ret = 0;
        while (right < nums.size())
        {
            if (nums[right] == 0)
            {
                zero++;
            }
            while (zero > k)
            {
                if (nums[left] == 0)
                {
                    zero--;
                }
                left++;
            }
            ret = max(ret, right - left + 1);
            right++;
        }
        return ret;

    }
};
///////////////////////////
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int left = 0, right = 0;
        int hush[128] = { 0 };
        int ret = 0;
        while (right < s.size()) {
            hush[s[right]] += 1;

            while (hush[s[right]] > 1) {
                hush[s[left]]--;
                left++;
            }
            ret = max(ret, right - left + 1);
            right++;
        }
        return ret;
    }
};